home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16719 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: hptemp1.cc.umr.edu!jlu
  2. From: jlu@cs.umr.edu (Eric Jui-Lin Lu)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help! Macro replacement......
  5. Date: 9 Apr 1996 20:11:46 GMT
  6. Organization: Computer Science Dept, Univ. of Missouri-Rolla
  7. Message-ID: <4kega2$1tk@hptemp1.cc.umr.edu>
  8. NNTP-Posting-Host: nag3.cs.umr.edu
  9.  
  10.  
  11. Hi *,
  12.  
  13. I wrote an ugly macro definition which, when I compiled, surprised
  14. me. The macro is defined as
  15.  
  16.    #define ABS(X) ((X <= 0) ? -X : X)
  17.  
  18. And I called the macro by using
  19.  
  20.    int y = ABS(-6+4);
  21.  
  22. I expected y would be 10. However, Solaris CC and Turbo C++ version 3.0
  23. for DOS returned compilation error. And IRIX CC and g++ version 2.6.3 
  24. and 2.7.0 returned 10.
  25.  
  26. The problem is clear that one replacement gives
  27.  
  28.    int y = --6+4;    // compilation error
  29.  
  30. And the other gives
  31.  
  32.    int y = - -6+4; // y = 10
  33.  
  34. I tried to find out the answer from Chap 16 of ANSI C++ standard 
  35. draft but cannot figure out which one is correct. Will someone 
  36. please EMAIL me which one conforms to ANSI C++? If interested, I 
  37. can post the summary. Thanks!
  38.  
  39.  
  40.   --Eric
  41.  
  42. -- 
  43. ***************************************---       Eric Jui-Lin Lu        ---*
  44. * Obviousness is always the enemy of  *   \      jlu@umr.edu           /   *
  45. * correctness.  -- Bertrand Russell   *   / http://www.cs.umr.edu/~jlu \   *
  46. ***************************************---   Univ. of Missouri-Rolla    ---*
  47.